//
//  JM_Login_VC.m
//  XiAnJMApp
//
//  Created by Kai Wang on 2017/5/22.
//  Copyright © 2017年 Kai Wang. All rights reserved.
//

#import "JM_Login_VC.h"
#import "Glb_M_VC.h"
#import "RootNavigationController.h"
#import "Common.h"
#import "Regist_VC.h"
#import "GCDSocketManager.h"
#import "TcpManager.h"


#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>
#import <unistd.h>

#import <arpa/inet.h>
#import <netdb.h>



#import "UDPManager.h"
@interface JM_Login_VC ()

/*
 * 背景图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *ImgV_Back;

/*
 * 实盘
 */
@property (weak, nonatomic) IBOutlet UIButton *btn_Firm;
- (IBAction)Action_Firm:(id)sender;




/*
 * 模拟
 */
@property (weak, nonatomic) IBOutlet UIButton *btn_moni;
- (IBAction)Action_Moni:(id)sender;



/*
 * 登录
 */
@property (weak, nonatomic) IBOutlet UIButton *btn_Login;
- (IBAction)Action_Login:(id)sender;



/*
 * 忘记密码
 */
@property (weak, nonatomic) IBOutlet UIButton *btn_ForgetPassword;

- (IBAction)Action_ForgetPassword:(id)sender;




/*
 * 免费注册
 */
@property (weak, nonatomic) IBOutlet UIButton *btn_Register;


- (IBAction)Action_Register:(id)sender;


@property (nonatomic,strong)GCDSocketManager * manager;



@end

@implementation JM_Login_VC

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createUI];
    
    
}
-(void)viewWillAppear:(BOOL)animated{

    if (self.navigationController) {
        [self.navigationController setNavigationBarHidden:YES animated:animated];
    }
}
-(void)createUI{
    self.view.backgroundColor=[UIColor whiteColor];
    _ImgV_Back.image=[UIImage imageNamed:@"Back1"];
    
    _btn_Login.backgroundColor=[UIColor clearColor];
    [_btn_Login.layer setCornerRadius:5.0]; //设置矩形圆角半径
    
    [_btn_Login.layer setBorderWidth:1.0]; //边框宽度
    
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 252.f/255.f,98.f/255.f,92.f/255.f , 1 });
    [_btn_Login.layer setBorderColor:colorref];//边框颜色
    
    [_btn_Login setTitle:@"实盘登录" forState:UIControlStateNormal];//button title
     [_btn_Login setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];//title color

//    _manager = [GCDSocketManager sharedSocketManager];
//    [_manager   connectToServer];

    UDPManager  *udp=[UDPManager sharedSocketManager];
    [udp        connectToServer];
    
//    
//    TcpManager *tcp = [TcpManager Share];
//    GCDAsyncSocket *socket = tcp.asyncsocket;
//    if (![socket connectToHost:@"101.37.86.94" onPort:50613 error:nil]) {
//        NSLog(@"fail to connect");
//    }
//    [socket readDataWithTimeout:3 tag:1];
//    [socket writeData:[@"LoginBeat\r&\r\n" dataUsingEncoding:NSUTF8StringEncoding] withTimeout:3 tag:1];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 * 实盘
 */
- (IBAction)Action_Firm:(id)sender {
    
    _ImgV_Back.image=[UIImage imageNamed:@"Back1"];
    [_btn_Login setTitle:@"实盘登录" forState:UIControlStateNormal];//button title


}



/*
 * 模拟
 */
- (IBAction)Action_Moni:(id)sender {
    
    _ImgV_Back.image=[UIImage imageNamed:@"Back2"];

    [_btn_Login setTitle:@"模拟登录" forState:UIControlStateNormal];//button title

    
}


/*
 * 登录
 */
- (IBAction)Action_Login:(id)sender {
   
    
    Glb_M_VC * VC =[[Glb_M_VC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
    
    [_manager Action_Login];
}

/*
 * 忘记密码
 */
- (IBAction)Action_ForgetPassword:(id)sender {
    
    
    
}


/*
 * 免费注册
 */
- (IBAction)Action_Register:(id)sender {
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Regist_VC" bundle:[NSBundle mainBundle]];
    UIViewController *Regist_VC = [story instantiateViewControllerWithIdentifier:@"Regist_VC"];
    
    [self.navigationController pushViewController:Regist_VC animated:YES];
    
    
}


//
//- (void)test
//{
//
//    
//    NSString * host =@"101.37.86.94";
//    NSNumber * port = @50613;
//    
//    // 创建 socket
//    int socketFileDescriptor = socket(AF_INET, SOCK_STREAM, 0);
//    if (-1 == socketFileDescriptor) {
//        NSLog(@"创建失败");
//        return;
//    }
//    
//    // 获取 IP 地址
//    struct hostent * remoteHostEnt = gethostbyname([host UTF8String]);
//    if (NULL == remoteHostEnt) {
//        close(socketFileDescriptor);
//        NSLog(@"%@",@"无法解析服务器的主机名");
//        return;
//    }
//    
//    struct in_addr * remoteInAddr = (struct in_addr *)remoteHostEnt->h_addr_list[0];
//    
//    // 设置 socket 参数
//    struct sockaddr_in socketParameters;
//    socketParameters.sin_family = AF_INET;
//    socketParameters.sin_addr = *remoteInAddr;
//    socketParameters.sin_port = htons([port intValue]);
//    
//    // 连接 socket
//    int ret = connect(socketFileDescriptor, (struct sockaddr *) &socketParameters, sizeof(socketParameters));
//    if (-1 == ret) {
//        close(socketFileDescriptor);
//        NSLog(@"连接失败");
//        return;
//    }
//    
//    NSLog(@"连接成功");
//}
//
//#pragma mark -socket的代理
//#pragma mark 连接成功
//-(void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port{
//    NSLog(@"%s",__func__);
//}
//
//
//#pragma mark 断开连接
//-(void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err{
//    if (err) {
//        NSLog(@"连接失败");
//    }else{
//        NSLog(@"正常断开");
//    }
//}
//
//
//#pragma mark 数据发送成功
//-(void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag{
//    NSLog(@"%s",__func__);
//    
//    //发送完数据手动读取，-1不设置超时
//    [sock readDataWithTimeout:-1 tag:tag];
//}
//
//#pragma mark 读取数据
//-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{
//    NSString *receiverStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%s %@",__func__,receiverStr);
//}


@end


























